<template>
  <div class="seach">
    <div class="seach_seach">

      <div class="seach_input1">
      <input type="email" class="form-control" id="exampleFormControlInput1_1" v-model="bookName" placeholder="请输入书名">
     </div>
      <!-- <el-button class="input_buttons">默认按钮</el-button> -->
      <el-button size="small" class="input_buttons" type="primary" @click="this.book_seach">搜索</el-button>
    </div>
    <div class="seach_body">
      <!-- 开始 -->
      <el-table :data="this.users_Info" border stripe><!-- 带边框、斑马纹 -->
        <!-- <el-table-column type="index"></el-table-column> -->
        <el-table-column label="图书编号" prop="bookId"></el-table-column>
        <el-table-column label="书名" prop="bookName"></el-table-column>
        <el-table-column label="作者" prop="author"></el-table-column>
        <el-table-column label="出版社" prop="publish"></el-table-column>
        <el-table-column label="图书类别" prop="category"></el-table-column>
        <el-table-column label="图书价格" prop="price"></el-table-column>
        <el-table-column label="归还时间" prop="deadline"  ></el-table-column>
        <!-- <el-table-column label="身份" prop="ismaind"></el-table-column>  -->

        <el-table-column label="操作" width="200px">
            <template slot-scope="scope">
              <el-tooltip effect="dark" content="加入书架" placement="top">
                  <el-button type="primary" icon="el-icon-plus" size="mini"  @click="updata_data(scope.row)"></el-button>
                </el-tooltip>
            </template>
        </el-table-column>
      <!-- </div> -->
      </el-table>
      <!-- 结束 -->
  
    </div>
    <div class="seach_bottom">
      <div class="bottom_buttons">
        <el-pagination
         background
         layout="prev, pager, next"
          @current-change="handleSizeChange"   
         @prev-click="handleCurrentChange"
         @next-click="handleCurrentChange"
         :total=this.total>
        </el-pagination>
      </div>
      <!-- <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum" :page-sizes="[1, 2, 5, 10]" :page-size="queryInfo.pagesize" 
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination> -->
    </div>
  </div>
</template>
<script>

import { log } from 'three';
export default({
  data(){
      return{
          bookName:"", 
          total:0,
          notice:false,
          delete:false,  
          users_Info:[
          ],
          tonote:{},
          test:[{bookId:"20100140205",bookName:"123455",author:"kuangfeng",publish:"男",category:"123456@qq.com",price:"12345678",deadline:0},
        ]
      }
  },

  
  methods:{
    async getUsersList() {
      this.axios.get('http://192.168.43.171:8081/books/page', {
                      // params:{
                      //  userId: this.account,        // 参数 id
                      //  psWord: this.password,
                      // }
                   // 参数 name
                }).then( (response)=> {
                  // if (response.data) {
                  //     alert("登陆成功")
                  //     // this.$router.push({ name: 'Index'})

                  // } else {
                  //     alert("登录失败")
                  //     // this.account='',
                  // }
                  console.log(response.data);
                  this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                  // this.total = res.data.total;
                  console.log("1234");
                  console.log(this.users_Info);
                }).catch(function (error) {
                  console.log(error);
                });
    // this.userList = res.data.users;
    // this.total = res.data.total;
    },
    // 当前页
    handleSizeChange(val) {
      console.log(`当前 ${val} 页`);
      this.axios.get('http://192.168.43.171:8081/books/page', {
                      params:{
                        key:val
                      }
                   // 参数 name
                }).then( (response)=> {
                  // if (response.data) {
                  //     alert("登陆成功")
                  //     // this.$router.push({ name: 'Index'})

                  // } else {
                  //     alert("登录失败")
                  //     // this.account='',
                  // }
                  console.log(response.data);
                  this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                  // this.total = res.data.total;
                  console.log("1234");
                  console.log(this.users_Info);
                }).catch(function (error) {
                  console.log(error);
                });
    },
    // 下一页或者上一页
    handleCurrentChange(val) {
      console.log(`去第 ${val}页`);
      this.axios.get('http://192.168.43.171:8081/books/page', {
                      params:{
                        key:val
                      }
                   // 参数 name
                }).then( (response)=> {
                  // if (response.data) {
                  //     alert("登陆成功")
                  //     // this.$router.push({ name: 'Index'})

                  // } else {
                  //     alert("登录失败")
                  //     // this.account='',
                  // }
                  console.log(response.data);
                  this.users_Info=response.data.data;
                    this.total=response.data.maxpage*10
                  // this.total = res.data.total;
                  console.log("1234");
                  console.log(this.users_Info);
                }).catch(function (error) {
                  console.log(error);
                });
    },
        // 给图书修改
    updata_data(row){
      console.log(typeof(row.bookId));
      this.axios.get('http://192.168.43.171:8081/bookshelf/insert', {
                    params:{
                      id:row.bookId
                    }
                 // 参数 name
              }).then( (response)=> {
                // this.getUsersList()
                this.$message({
                message: response.data.msg,
                type: 'success'
               });
              }).catch(function (error) {
                console.log(error);
              });
    },

    // seach book
    book_seach(){
    console.log(this.userName);
    this.axios.get('http://192.168.43.171:8081/books/page', {
                    params:{
                      key:0,
                      bookName:this.bookName,
                    }
                 // 参数 name
              }).then( (response)=> {
                this.total=response.data.maxpage*10
                console.log(response);
                this.users_Info=response.data.data;
              }).catch(function (error) {
                console.log(error);
              });
  }
  },
  mounted(){
        // 绑定事
        this.$bus.$on ('bus_delete_cancel', (data) => {
          this.delete=data;
          // console.log(data);
          if(data==1){
            this.delete=false
          }
        }),
        this.$bus.$on ('bus_delete', (data) => {
          // this.delete=data;
          console.log(data);
          if(data==1){
            this.delete=false
          }
        })
        this.$bus.$on ('bus_up_date_cancel', (data) => {
          // this.delete=data;
          if(data==1){
            this.notice=false
          }
        })
        this.$bus.$on ('bus_up_date', (data) => {
          // this.delete=data;
          if(data==1){
            this.notice=false
          }
        })
        this.getUsersList();
    },
    beforeDestroy(){
        // this.$bus.$off('bus_delete_cancel')
        this.$bus.$off('bus_delete')
        this.$bus.$off('bus_updata_cancel')
        this.$bus.$off('bus_updata')
        
      },
})
</script>
<style lang="less" scoped>
.seach{
  width: 100%;
  height: 100%;
  position: absolute;
  .seach_seach{
    position: absolute;
    right: 50px;
    height: 6%;
    width: 70%;
    // background-color: #67c58b;
    .seach_input{
       position: absolute;
       width: 40%;
       top: 4px;
       left: 50;
    }
    .seach_input1{
     position: absolute;
     width: 40%;
     top: 4px;
     left: 358px;
  }
    .input_buttons{
     position: absolute;
     top: 16%;
     right: 11%;
    }
  }
  .seach_body{
  // background-color: aquamarine;
  // background-color: rgb(245, 243, 243);
  background-color: #fff;
  position: absolute;
  top: 7%;
  height: 80%;
  width: 100%;
  td{
    background-color: #fff;
  }
  }

  .seach_bottom{
    // background-color: #5f9ca1;
    height: 10%;
    width: 100%;
    bottom: 1%;
    position: absolute;
    .bottom_buttons{
      position: absolute;
      top: 32%;
      height: 40%;
      width: 20%;
      left: 25%;
      // transform: translate(-50%,-50%);
      // background-color: bisque;
    }

  }
}
</style>